#include "includes.h"

int main (int argc, char *argv[])
{
	bool autoPlay = false;
  board myBoard;
	char buffer[80] = {0};
	char buffer2[6] = {0};
	int badMove = 1;

	if (argc > 1)
	{
		if (argc > 2)
			printUsage();
		else if (!strcmp(argv[1], "-a"))
			autoPlay = true;
		else
			printUsage();
	}

  debug(1, "entering main()");

  srand(time(0));
  newBoard(&myBoard);
  
  while(!isGameOver(&myBoard))
  {
		printf("\n");
		printBoard(&myBoard);

		//white moves
		if (autoPlay)
		{
//			dumpBoard(&myBoard);
			move(&myBoard, best_move(&myBoard));
		}
		else
		{
			badMove = 1;
			while(badMove)
			{
				fgets(buffer, 79, stdin);

				if(!strcmp("d\n", buffer))
					dumpBoard(&myBoard);
				else
				{
					strncpy(buffer2, buffer, 5);
					buffer2[5] = 0;
					badMove = humanMove(&myBoard, buffer2);
				}
			}
		}

		//black moves
		printf("\n");
		printBoard(&myBoard);
//		dumpBoard(&myBoard);
	  move(&myBoard, best_move(&myBoard));
  }

  printf("\n");
  printBoard(&myBoard);

  debug(1, "exiting main()");

  return 0;
}

